﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace XRPGLibrary.Controls
{
    public class PictureBox : Control
    {
        #region Field Region
        Texture2D image;//控件中加载的图片
        Rectangle sourceRect;//图片的长度矩形
        Rectangle destRect;//图片在窗体上呈现的矩形
        #endregion
        #region Property Region
        public Texture2D Image
        {
            get { return image; }
            set { image = value; }
        }
        public Rectangle SourceRectangle
        {
            get { return sourceRect; }
            set { sourceRect = value; }
        }
        public Rectangle DestinationRectangle
        {
            get { return destRect; }
            set { destRect = value; }
        }
        #endregion
        #region Constructors构造函数的重载
        public PictureBox(Texture2D image, Rectangle destination)
        {
            Image = image;
            DestinationRectangle = destination;
            SourceRectangle = new Rectangle(0, 0, image.Width, image.Height);//原图片大小
            Color = Color.White;
        }
        public PictureBox(Texture2D image, Rectangle destination, Rectangle source)
        {
            Image = image;
            DestinationRectangle = destination;
            SourceRectangle = source;
            Color = Color.White;
        }
        #endregion
        #region Abstract Method Region//来自于继承类的方法重载
        public override void Update(GameTime gameTime)
        { }
        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(image, destRect, sourceRect, Color);
        }
        public override void HandleInput(PlayerIndex playerIndex)
        {
        }
        #endregion
        #region Picture Box Methods//为新的图片框设定位置
        public void SetPosition(Vector2 newPosition)
        {
            destRect = new Rectangle(
            (int)newPosition.X,
            (int)newPosition.Y,
            sourceRect.Width,
            sourceRect.Height);
        }
        #endregion
    }
}